#!/bin/bash

# Function to display help information
show_help() {
    echo "Usage: $0 [options]"
    echo
    echo "Options:"
    echo "  -h, --help    Show this help message and exit"
    echo "  -d, --directory  Create a Directory"
}

# create role Directory structure diagram
create_role_dir() {
  mkdir ../roles/$1/{files,templates,tasks,handlers,vars,defaults,meta} -p   

  # 遍历目录下的所有文件夹
  for dir in "../roles/$1"/*/; do
    if [ -d "$dir" ]; then
      # 在每个文件夹中创建一个空文件
      touch "$dir/README.md"
    fi
  done
}

# Check if no arguments were provided
if [ $# -eq 0 ]; then
    show_help
    exit 1
fi

# Process the arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        -h|--help)
            show_help
            exit 0
            ;;
        -d|--directory)
	    if [ -n "$2" ]; then
                option_arg=$2
		echo $2
		create_role_dir $2
                shift # Shift past the argument
            else
                echo "Error: -o option requires an argument."
                exit 1
            fi
            ;;
        *)
            echo "Unknown option: $1"
            show_help
            exit 1
            ;;
    esac
    shift # Shift to the next argument
done
